Imports ADOConnection
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient

Public Class CNhomQuyen
    Private _ban_id As Integer
    Private _phieunhap As Boolean
    Private _ghiphieunhap As Boolean
    Private _phieuxuat As Boolean
    Private _ghiphieuxuat As Boolean

    Public Property Ban_ID() As Integer
        Get
            Return _ban_id
        End Get
        Set(ByVal Value As Integer)
            _ban_id = Value
        End Set
    End Property

    Public Property PhieuNhap() As Boolean
        Get
            Return _phieunhap
        End Get
        Set(ByVal Value As Boolean)
            _phieunhap = Value
        End Set
    End Property

    Public Property GhiPhieuNhap() As Boolean
        Get
            Return _ghiphieunhap
        End Get
        Set(ByVal Value As Boolean)
            _ghiphieunhap = Value
        End Set
    End Property

    Public Property PhieuXuat() As Boolean
        Get
            Return _phieuxuat
        End Get
        Set(ByVal Value As Boolean)
            _phieuxuat = Value
        End Set
    End Property

    Public Property GhiPhieuXuat() As Boolean
        Get
            Return _ghiphieuxuat
        End Get
        Set(ByVal Value As Boolean)
            _ghiphieuxuat = Value
        End Set
    End Property
End Class

Public Class CNhomQuyens
    Public Shared Function GetQuyenByMa(ByVal pBan_ID As String) As CNhomQuyen
        Dim KQ As New CNhomQuyen
        Dim strSQL As String

        strSQL = "SELECT * FROM tblNhomQuyen" & _
            " WHERE ban_id = '" & pBan_ID & "'"

        Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
        Dim objCommand As IDbCommand = objConnection.CreateCommand(strSQL)
        Dim objReader As CDataReader = Nothing

        Try
            objReader = objConnection.GetDataReader(objCommand, False)
            If objReader.Read = True Then
                With KQ
                    .Ban_ID = objReader.GetInt32(0)
                    .PhieuNhap = objReader.GetBoolean(1)
                    .GhiPhieuNhap = objReader.GetBoolean(2)
                    .PhieuXuat = objReader.GetBoolean(3)
                    .GhiPhieuXuat = objReader.GetBoolean(4)
                End With
            End If

        Catch ex As System.Exception
            Throw ex
        Finally
            If Not IsNothing(objReader) Then
                objReader.Close()
            End If
            objConnection.Close()
        End Try
        Return KQ
    End Function
End Class

Public Class CUser
    Private _user_id As Integer
    Private _loginname As String
    Private _pass As String
    Private _fullname As String
    Private _ban_id As Integer
    Private _isadmin As Boolean
    Private _ishide As Boolean
    Private _ghichu As String

    Public Property User_ID() As Integer
        Get
            Return _user_id
        End Get
        Set(ByVal Value As Integer)
            _user_id = Value
        End Set
    End Property

    Public Property LoginName() As String
        Get
            Return _loginname
        End Get
        Set(ByVal Value As String)
            _loginname = Value
        End Set
    End Property

    Public Property FullName() As String
        Get
            Return _fullname
        End Get
        Set(ByVal Value As String)
            _fullname = Value
        End Set
    End Property

    Public Property Pass() As String
        Get
            Return _pass
        End Get
        Set(ByVal Value As String)
            _pass = Value
        End Set
    End Property

    Public Property Ban_ID() As Integer
        Get
            Return _ban_id
        End Get
        Set(ByVal Value As Integer)
            _ban_id = Value
        End Set
    End Property

    Public Property IsAdmin() As Boolean
        Get
            Return _isadmin
        End Get
        Set(ByVal Value As Boolean)
            _isadmin = Value
        End Set
    End Property

    Public Property IsHide() As Boolean
        Get
            Return _ishide
        End Get
        Set(ByVal Value As Boolean)
            _ishide = Value
        End Set
    End Property

    Public Property GhiChu() As String
        Get
            Return _ghichu
        End Get
        Set(ByVal Value As String)
            _ghichu = Value
        End Set
    End Property

    Public Overrides Function ToString() As String
        Return _loginname
    End Function
End Class

Public Class CUsers
    Public Shared Function GetGiaTriThanhPhan(ByVal sConnString As String, ByVal pName As String) As String
        Dim KQ As String = ""
        Dim strTP As String = ""
        Dim data() As String = sConnString.Split(";")
        For i As Integer = 0 To data.GetUpperBound(0)
            If data(i).IndexOf(pName) > -1 Then
                strTP = data(i)
                Exit For
            End If
        Next
        Dim data2() As String = strTP.Split("=")
        If data2.GetUpperBound(0) > 0 Then
            KQ = data2(1)
        End If
        Return KQ
    End Function

    Public Shared Function DuocPhepChay(ByVal pLoginName As String, ByVal pPass As String, ByRef objUser As CUser) As Boolean
        Dim KQ As Boolean = False
        Dim strSQL As String

        strSQL = "SELECT user_id, loginname, cast(pass as varchar(30)) as pass, fullname, ban_id, isadmin, ishide, ghichu FROM tblUser" & _
                " WHERE loginname = '" + pLoginName + "' and pass = cast('" + pPass + "' as varbinary(30))"

        Try
            Dim objReader As SqlDataReader = BaseDB.ExecSql_DataReader(strSQL)
            If objReader.Read Then
                objUser = New CUser
                With objUser
                    .User_ID = objReader.GetInt16(0)
                    .LoginName = objReader.GetString(1)
                    .Pass = objReader.GetString(2)
                    .FullName = objReader.GetString(3)
                    .Ban_ID = objReader.GetInt32(4)
                    .IsAdmin = objReader.GetBoolean(5)
                    .IsHide = objReader.GetBoolean(6)
                    .GhiChu = objReader.GetString(7)
                End With
                KQ = True
            End If

            If Not IsNothing(objReader) Then
                objReader.Close()
            End If
        Catch ex As System.Exception
            Throw ex
        End Try
        Return KQ
    End Function

    Public Shared Function GetUserByName(ByVal pLoginName As String) As CUser
        Dim KQ As New CUser
        Dim strSQL As String

        strSQL = "SELECT user_id, loginname, cast(pass as varchar(30)) as pass, fullname, ban_id, isadmin, ishide, ghichu FROM tblUser" & _
            " WHERE loginname = '" & pLoginName & "'"

        Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
        Dim objCommand As IDbCommand = objConnection.CreateCommand(strSQL)
        Dim objReader As CDataReader = Nothing

        Try
            objReader = objConnection.GetDataReader(objCommand, False)
            If objReader.Read = True Then
                With KQ
                    .User_ID = objReader.GetInt16(0)
                    .LoginName = objReader.GetString(1)
                    .Pass = objReader.GetString(2)
                    .FullName = objReader.GetString(3)
                    .Ban_ID = objReader.GetInt32(4)
                    .IsAdmin = objReader.GetBoolean(5)
                    .IsHide = objReader.GetBoolean(6)
                    .GhiChu = objReader.GetString(7)
                End With
            End If

        Catch ex As System.Exception
            Throw ex
        Finally
            If Not IsNothing(objReader) Then
                objReader.Close()
            End If
            objConnection.Close()
        End Try

        Return KQ
    End Function

   

    'Kiem tra xem co quyen admin cua SQL Server luon khong
    Public Shared Function isSysAdmin(ByVal pUserName As String) As Boolean
        Dim KQ As Boolean = False
        Try
            Dim strIsAdmin As String = "select IS_SRVROLEMEMBER('sysadmin','" + pUserName + "')"
            Dim value As Integer = BaseDB.ExecSql_DataValue(strIsAdmin)
            If value = 1 Then
                KQ = True
            End If
        Catch ex As Exception
            Throw ex
        End Try
        Return KQ
    End Function

    'Kiem tra xem co quyen admin cua chuong trinh hay khong
    Public Shared Function isAdmin(ByVal pUserName As String) As Boolean
        Dim KQ As Boolean = False
        Try
            Dim strIsAdmin As String = "select isAdmin from tblUser where loginname = N'" + pUserName + "'"
            KQ = BaseDB.ExecSql_DataValue(strIsAdmin)
        Catch ex As Exception
            Throw ex
        End Try
        Return KQ
    End Function

    'Public Shared Function GetUserList0() As ArrayList
    '    Dim aryItems As New ArrayList
    '    Try
    '        Dim oServer As SQLDMO.SQLServer

    '        ' Create a server object and connect.
    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        Dim oDbUser As SQLDMO.User
    '        Dim oDB As SQLDMO.Database = oServer.Databases.Item(gDBName)

    '        For Each oDbUser In oDB.Users
    '            Dim oUser As New CUser
    '            'oUser.User = oDbUser
    '            aryItems.Add(oUser)
    '        Next
    '    Catch ex As Exception
    '        'MsgBox(ex.Message)
    '        Throw ex
    '    End Try

    '    Return aryItems
    'End Function

    'Public Shared Function GetUserList() As ArrayList

    '    Dim aryItems As New ArrayList
    '    Dim strSQL As String

    '    strSQL = "SELECT * FROM tblUser"

    '    Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
    '    Dim objCommand As IDbCommand = objConnection.CreateCommand(strSQL)
    '    Dim objReader As CDataReader = Nothing

    '    Try
    '        objReader = objConnection.GetDataReader(objCommand, False)
    '        While objReader.Read
    '            Dim oUser As New CUser
    '            With oUser
    '                .User_ID = objReader.GetInt16(0)
    '                .LoginName = objReader.GetString(1)
    '                .Password = objReader.GetString(2)
    '                .FullName = objReader.GetString(3)
    '                .Ban_ID = objReader.GetInt32(4)
    '                .IsAdmin = objReader.GetBoolean(5)
    '                .IsHide = objReader.GetBoolean(6)
    '                .GhiChu = objReader.GetString(7)
    '            End With
    '            aryItems.Add(oUser)
    '        End While
    '    Catch ex As System.Exception
    '        Throw ex
    '    Finally
    '        If Not IsNothing(objReader) Then
    '            objReader.Close()
    '        End If
    '        objConnection.Close()
    '    End Try
    '    Return aryItems
    'End Function

    'Public Shared Function Insert(ByVal oUser As CUser) As Long
    '    Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
    '    Dim objDBUtility As IDBUtility = objConnection.DBUtility

    '    Dim objStringBuilder As New StringBuilder(200)
    '    With objStringBuilder
    '        .Append("INSERT INTO tblUser" & _
    '                " (loginname,fullname,Ban_ID, ghichu) VALUES(")
    '        .Append(objDBUtility.GetParamPlaceHolder("loginname", True))
    '        .Append(objDBUtility.GetParamPlaceHolder("fullname", True))
    '        .Append(objDBUtility.GetParamPlaceHolder("Ban_ID", True))
    '        .Append(objDBUtility.GetParamPlaceHolder("ghichu", False))
    '        .Append(")")
    '    End With

    '    Dim sInsert As String = objStringBuilder.ToString

    '    Dim objCommand As IDbCommand = objConnection.CreateCommand(sInsert)
    '    Dim objTransaction As IDbTransaction = objConnection.BeginTransaction
    '    Dim lSerialKey As Long = 0

    '    Try
    '        With objCommand
    '            .Transaction = objTransaction
    '            .Parameters.Add(objDBUtility.CreateParameter("loginname", DbType.String, oUser.LoginName, oUser.LoginName.Length))
    '            .Parameters.Add(objDBUtility.CreateParameter("fullname", DbType.String, oUser.FullName, oUser.FullName.Length))
    '            .Parameters.Add(objDBUtility.CreateParameter("Ban_ID", DbType.Int32, oUser.Ban_ID, 0))
    '            .Parameters.Add(objDBUtility.CreateParameter("GhiChu", DbType.String, oUser.GhiChu, oUser.GhiChu.Length))
    '        End With

    '        lSerialKey = objDBUtility.InsertAndReturnSerialKey(objCommand, "user_id", "tblUser")
    '        objTransaction.Commit()

    '    Catch ex As System.Exception
    '        objTransaction.Rollback()
    '        Throw ex
    '    Finally
    '        objConnection.Close()
    '    End Try
    '    Return lSerialKey
    'End Function

    'Public Shared Function Update(ByVal oUser As CUser) As Long

    '    Dim lRowsAffected As Long = 0
    '    Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
    '    Dim objDBUtility As IDBUtility = objConnection.DBUtility

    '    Dim strSQL As String = "UPDATE tblUser SET"
    '    strSQL &= " Ban_ID = " & objDBUtility.GetParamPlaceHolder("Ban_ID", True)
    '    strSQL &= " trangthai = " & objDBUtility.GetParamPlaceHolder("trangthai", True)
    '    strSQL &= " luutrangthai = " & objDBUtility.GetParamPlaceHolder("luutrangthai", True)
    '    strSQL &= " ghichu = " & objDBUtility.GetParamPlaceHolder("ghichu", False)
    '    strSQL &= " WHERE loginname = " & objDBUtility.GetParamPlaceHolder("loginname", False)

    '    Dim objTransaction As IDbTransaction = objConnection.BeginTransaction
    '    Dim objCommand As IDbCommand = objConnection.CreateCommand(strSQL)

    '    Try
    '        With objCommand
    '            .Transaction = objTransaction
    '            .Parameters.Add(objDBUtility.CreateParameter("Ban_ID", DbType.Int32, oUser.Ban_ID, 0))
    '            .Parameters.Add(objDBUtility.CreateParameter("trangthai", DbType.Boolean, oUser.TrangThai, 1))
    '            .Parameters.Add(objDBUtility.CreateParameter("luutrangthai", DbType.Boolean, oUser.LuuTrangThai, 1))
    '            .Parameters.Add(objDBUtility.CreateParameter("ghichu", DbType.String, oUser.GhiChu, oUser.GhiChu.Length))
    '            .Parameters.Add(objDBUtility.CreateParameter("loginname", DbType.String, oUser.LoginName, oUser.LoginName.Length))
    '            lRowsAffected = .ExecuteNonQuery()
    '            objTransaction.Commit()
    '        End With

    '    Catch ex As System.Exception
    '        objTransaction.Rollback()
    '        Throw ex
    '    Finally
    '        objConnection.Close()
    '    End Try

    '    Return lRowsAffected

    'End Function

    'Public Shared Function Delete(ByVal pUser_ID As Integer) As Long
    '    Dim lRowsAffected As Long = 0
    '    Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
    '    Dim objDBUtility As IDBUtility = objConnection.DBUtility

    '    Dim objStringBuilder As New StringBuilder(150)
    '    With objStringBuilder
    '        .Append("DELETE FROM tblUser ")
    '        .Append(" WHERE user_id = ")
    '        .Append(objDBUtility.GetParamPlaceHolder("user_id", False))
    '    End With
    '    Dim sUpdate As String = objStringBuilder.ToString

    '    Dim objTransaction As IDbTransaction = objConnection.BeginTransaction
    '    Dim objCommand As IDbCommand = objConnection.CreateCommand(sUpdate)

    '    Try
    '        With objCommand
    '            .Transaction = objTransaction
    '            .Parameters.Add(objDBUtility.CreateParameter("user_id", DbType.Int16, pUser_ID, 0))
    '            lRowsAffected = .ExecuteNonQuery()
    '            objTransaction.Commit()
    '        End With

    '    Catch ex As System.Exception
    '        objTransaction.Rollback()
    '        Throw ex
    '    Finally
    '        objConnection.Close()
    '    End Try

    '    Return lRowsAffected

    'End Function

    'Public Shared Function DeleteUser0(ByVal pUserName As String) As Boolean
    '    Dim KQ As Boolean = False
    '    Try
    '        Dim oServer As SQLDMO.SQLServer
    '        'Dim oLogin As SQLDMO.Login

    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        'Dim oDbUser As SQLDMO.User
    '        Dim oDB As SQLDMO.Database = oServer.Databases.Item(gDBName)
    '        oDB.Users.Remove(pUserName)

    '        oServer.Logins.Remove(pUserName)
    '        KQ = True
    '    Catch ex As Exception
    '        MsgBox(ex.Message)
    '    End Try

    '    Return KQ
    'End Function

    'Public Shared Function DeleteUser(ByVal pUserName As String) As Boolean
    '    Dim KQ As Boolean = False
    '    If DropUser(pUserName) = True Then
    '        KQ = DropLogin(pUserName)
    '    End If
    '    Return KQ
    'End Function

    'Private Shared Function DropLogin(ByVal pLoginName As String) As Boolean
    '    Dim KQ As Boolean = False
    '    'sp_droplogin 'Victoria'

    '    Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
    '    Dim strSQL As String = "sp_droplogin '" & pLoginName & "'"
    '    'Dim objTransaction As IDbTransaction = objConnection.BeginTransaction
    '    Dim objCommand As IDbCommand = objConnection.CreateCommand(strSQL)
    '    Try
    '        With objCommand
    '            '.Transaction = objTransaction
    '            .CommandType = CommandType.Text
    '            .CommandText = strSQL
    '            .ExecuteNonQuery()
    '        End With
    '        KQ = True
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objConnection.Close()
    '    End Try

    '    Return KQ
    'End Function

    'Private Shared Function DropUser(ByVal pUserName As String) As Boolean
    '    Dim KQ As Boolean = False
    '    'sp_dropuser 'Albert'

    '    Dim objConnection As IADOConnection = g_objConnFactory.GetConnection
    '    Dim strSQL As String = "sp_dropuser '" & pUserName & "'"
    '    'Dim objTransaction As IDbTransaction = objConnection.BeginTransaction
    '    Dim objCommand As IDbCommand = objConnection.CreateCommand(strSQL)
    '    Try
    '        With objCommand
    '            '.Transaction = objTransaction
    '            .CommandType = CommandType.Text
    '            .CommandText = strSQL
    '            .ExecuteNonQuery()
    '        End With

    '        KQ = True
    '    Catch ex As Exception
    '        Throw ex
    '    Finally
    '        objConnection.Close()
    '    End Try

    '    Return KQ
    'End Function

    'Public Shared Function AddUser(ByVal pUserName As String, ByVal pUserPass As String) As Boolean
    '    Dim KQ As Boolean = False

    '    Try
    '        ' Declare variables.
    '        Dim oServer As SQLDMO.SQLServer
    '        Dim oLogin As SQLDMO.Login

    '        ' Create a server object and connect.
    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        'oLogin = oServer.Logins.Item(pUserName)
    '        Dim bFound As Boolean = False
    '        For i As Integer = 1 To oServer.Logins.Count
    '            oLogin = oServer.Logins.Item(i)
    '            If oLogin.Name = pUserName Then
    '                bFound = True
    '                Exit For
    '            End If
    '        Next

    '        If bFound = False Then
    '            ' Create the Login object.
    '            oLogin = CreateObject("SQLDMO.Login")

    '            ' Set the appropriate properties.
    '            oLogin.Name = pUserName
    '            oLogin.Type = SQLDMO.SQLDMO_LOGIN_TYPE.SQLDMOLogin_Standard
    '            oLogin.SetPassword("", pUserPass)
    '            oLogin.Database = gDBName '"MoiTruong"

    '            ' Add the Login object to the server's Logins collection.
    '            oServer.Logins.Add(oLogin)
    '        End If

    '        Dim oDB As SQLDMO.Database = oServer.Databases.Item(gDBName)
    '        Dim oUser As SQLDMO.User = Nothing
    '        bFound = False
    '        For i As Integer = 1 To oDB.Users.Count
    '            oUser = oDB.Users.Item(i)
    '            If (oUser.Name = pUserName) Or (oUser.Login = pUserName) Then
    '                bFound = True
    '                Exit For
    '            End If
    '        Next

    '        If bFound = False Then
    '            ' Create the User object.
    '            oUser = CreateObject("SQLDMO.User")
    '            oUser.Name = pUserName
    '            oUser.Login = pUserName
    '            oDB.Users.Add(oUser)
    '        End If

    '        AddMember(oUser.Name, "db_datareader")
    '        AddMember(oUser.Name, "db_datawriter")

    '        KQ = True
    '    Catch ex As Exception
    '        MsgBox(ex.Message)
    '    End Try

    '    Return KQ

    'End Function

    'Public Shared Function isSecuAdmin(ByVal pUserName As String) As Boolean
    '    Dim KQ As Boolean = False
    '    Try
    '        ' Declare variables.
    '        Dim oServer As SQLDMO.SQLServer
    '        Dim oLogin As SQLDMO.Login

    '        ' Create a server object and connect.
    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        oLogin = oServer.Logins.Item(pUserName)
    '        KQ = oLogin.IsMember("securityadmin")
    '    Catch ex As Exception
    '        Throw ex
    '    End Try

    '    Return KQ

    'End Function



   

    ''Public Shared Function isSysAdmin(ByVal pUserName As String) As Boolean
    ''    Dim KQ As Boolean = False
    ''    Try
    ''        ' Declare variables.
    ''        Dim oServer As SQLDMO.SQLServer
    ''        Dim oLogin As SQLDMO.Login

    ''        ' Create a server object and connect.
    ''        oServer = CreateObject("SQLDMO.SQLServer")

    ''        'Dim oServer As SQLDMO.SQLServer
    ''        Dim mSQLServer = GetGiaTriThanhPhan(myConnStr, "Data Source")
    ''        'Dim mDBName = CUsers.GetGiaTriThanhPhan(myConnStr, "Initial Catalog")
    ''        oServer = CreateObject("SQLDMO.SQLServer")
    ''        oServer.Connect(mSQLServer, g_UserName, g_Password)

    ''        'oServer.Connect(gSQLServer, gSAName, gSAPassword)

    ''        oLogin = oServer.Logins.Item(pUserName)
    ''        KQ = oLogin.IsMember("sysadmin")
    ''    Catch ex As Exception
    ''        Throw ex
    ''    End Try

    ''    Return KQ
    ''End Function

    'Public Shared Function AddMember(ByVal pUserName As String, ByVal pRoleName As String) As Boolean
    '    Dim KQ As Boolean = False

    '    Try
    '        ' Declare variables.
    '        Dim oServer As SQLDMO.SQLServer
    '        'Dim oLogin As SQLDMO.Login

    '        ' Create a server object and connect.
    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        Dim oDB As SQLDMO.Database = oServer.Databases.Item(gDBName)
    '        Dim oDbRole As SQLDMO.DatabaseRole
    '        oDbRole = oDB.DatabaseRoles.Item(pRoleName)
    '        oDbRole.AddMember(pUserName)

    '        KQ = True
    '    Catch ex As Exception
    '        Throw ex
    '    End Try

    '    Return KQ

    'End Function

    'Public Shared Function DropMember(ByVal pUserName As String, ByVal pRoleName As String) As Boolean
    '    Dim KQ As Boolean = False

    '    Try
    '        ' Declare variables.
    '        Dim oServer As SQLDMO.SQLServer
    '        'Dim oLogin As SQLDMO.Login

    '        ' Create a server object and connect.
    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        Dim oDB As SQLDMO.Database = oServer.Databases.Item(gDBName)
    '        Dim oDbRole As SQLDMO.DatabaseRole
    '        oDbRole = oDB.DatabaseRoles.Item(pRoleName)
    '        oDbRole.DropMember(pUserName)

    '        KQ = True
    '    Catch ex As Exception
    '        Throw ex
    '    End Try

    '    Return KQ

    'End Function

    'Public Shared Function AddSMember(ByVal pUserName As String, ByVal pRoleName As String) As Boolean
    '    Dim KQ As Boolean = False

    '    Try
    '        ' Declare variables.
    '        Dim oServer As SQLDMO.SQLServer
    '        'Dim oLogin As SQLDMO.Login

    '        ' Create a server object and connect.
    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        'Dim oDB As SQLDMO.Database = oServer.Databases.Item(gDBName)
    '        Dim oSRole As SQLDMO.ServerRole
    '        oSRole = oServer.ServerRoles.Item(pRoleName)
    '        oSRole.AddMember(pUserName)

    '        KQ = True
    '    Catch ex As Exception
    '        Throw ex
    '    End Try
    '    Return KQ
    'End Function

    'Public Shared Function DropSMember(ByVal pUserName As String, ByVal pRoleName As String) As Boolean
    '    Dim KQ As Boolean = False

    '    Try
    '        ' Declare variables.
    '        Dim oServer As SQLDMO.SQLServer
    '        'Dim oLogin As SQLDMO.Login

    '        ' Create a server object and connect.
    '        oServer = CreateObject("SQLDMO.SQLServer")
    '        oServer.Connect(gSQLServer, gSAName, gSAPassword)

    '        'Dim oDB As SQLDMO.Database = oServer.Databases.Item(gDBName)
    '        Dim osRole As SQLDMO.ServerRole
    '        osRole = oServer.ServerRoles.Item(pRoleName)
    '        osRole.DropMember(pUserName)

    '        KQ = True
    '    Catch ex As Exception
    '        Throw ex
    '    End Try
    '    Return KQ
    'End Function
End Class